//
//  YHRouter.h
//  MoreCoin
//
//  Created by 林宁宁 on 2019/9/19.
//  Copyright © 2019 MoreCoin. All rights reserved.
//
//  参考 JXBRouter

#import <Foundation/Foundation.h>
#import "YHRouterParam.h"

NS_ASSUME_NONNULL_BEGIN

/// 获取应用当前的控制器
UIViewController * _Nullable YHCurrentViewController(void);
UINavigationController * YHCurrentNavigationViewController(void);

#pragma mark - -------------------

typedef NS_ENUM(NSInteger, YHRouterErrorCode) {
    /// Bifrost 注册的handle操作是空的
    YHRouterErrorCodeBFUrlHandlerNotFound,
    /// Bifrost 找不到该module
    YHRouterErrorCodeBFModuleNotFoundException,
    /// Bifrost 没有找到方法实现
    YHRouterErrorCodeBFAPINotFoundException,
    /// Bifrost module注册失败
    YHRouterErrorCodeBFFailedToRegisterModule,
    /// map Key 格式错误
    YHRouterErrorCodeKeyMapFormatError,
    /// 没有找到导航条
    YHRouterErrorCodeNavigationNotFound,
    /// URL跳转 Scheme不匹配
    YHRouterErrorCodeURLSchemeMismatch,
    /// 配置 缺少 不全
    YHRouterErrorCodeConfigIncomplete,
    /// 通过Key没有找到
    YHRouterErrorCodeKeyMapNotFound,
    /// 通过className没有找到class
    YHRouterErrorCodeClassNotFound,
    /// 该控制器只能有一个
    YHRouterErrorCodeControllerSingleton,
    /// 需要登录操作
    YHRouterErrorCodeNeedLogin,
    
    /// 配置config操作中断了跳转
    YHRouterErrorCodeConfigOpertionBreakOff,

};

/** 跳转路由*/
@interface YHRouter : NSObject

/// 再传入 URL的情况下
/// 如果有设置 不是这个scheme类型 都过滤掉
/// 未 设置不做过滤
@property (copy, nonatomic) NSString * urlScheme;
/// 导航条控制器 默认UINavigationController
@property (assign, nonatomic) Class navigationViewClass;
/// 控制器映射表 "viewcontrollername": @["tag1","tage2",@(1),@(100)]
/// 在+load中 通过 yh_bindKeys 绑定
@property (retain, nonatomic) NSMutableDictionary <NSString *, NSArray *> * mapKeys;
/// URL中可以读取控制器page的 key 字符串信息
@property (retain, nonatomic) NSArray <NSString *>* URLPageKeypaths;
/// 异常处理
@property (copy, nonatomic) void(^errorHandler)(YHRouterErrorCode code, NSString * exceptionDescription);

+ (instancetype)sharedManager;

/// MARK: - Push Present

/// vcKey 是控制器的名字，或者在YHRouter+Map中绑定的Key
+ (UIViewController *)yh_pushKey:(NSString *)vcKey;
+ (UIViewController *)yh_pushKey:(NSString *)vcKey params:(YHRouterParam * _Nullable)params;
/// config如果返回空则不做跳转操作
+ (UIViewController *)yh_pushKey:(NSString *)vcKey config:(UIViewController * _Nullable(^ _Nullable)(UIViewController * vc))config;


+ (UIViewController *)yh_presentKey:(NSString *)vcKey;
+ (UIViewController *)yh_presentKey:(NSString *)vcKey params:(YHRouterParam * _Nullable)params;
+ (UIViewController *)yh_presentKey:(NSString *)vcKey config:(UIViewController * _Nullable(^ _Nullable)(UIViewController * vc))config;


+ (void)yh_presentViewController:(UIViewController *)vc;
+ (void)yh_pushViewController:(UIViewController *)vc;


/// MARK: - URL
/// 通过URL跳转 内部含 控制器名称的参数信息
/// [YHRouter yh_openURL:@"mocr://quick?id=12&type=22"];  quick是key
/// scheme://keypayge?param1=1&param2=2
+ (UIViewController *)yh_openURL:(NSString *)URL;

/// 通过URL跳转 内部含 控制器名称的参数信息 跳转page
/// https://host?page=helpCenter
+ (UIViewController *)yh_openUniversalLink:(NSString *)routePattern;


@end

NS_ASSUME_NONNULL_END
